import {getFrontendCareerInfoById, likeQuery, likeQueryByName} from "@/api/career";

const state = {
    list: [],
    total: 0
}

const mutations = {
    /**
     * 保存所有岗位信息到Vuex中
     * @param {*} state
     * @param {*} data
     */
    SET_CAREERLIST: (state, data) => {
        state.list = data.records
        state.total = data.total
    },
}

const actions = {
    /**
     * 获取所有岗位信息
     * @param {*} param0
     * @returns
     */
    likeQuery({ commit }, data) {
        return new Promise((resolve, reject) => {
            likeQuery(data).then(
                resp => {
                    const { data } = resp.data
                    commit('SET_CAREERLIST',data)
                    resolve(resp.data)
                }).catch(
                error => {
                    reject(error)
                })
        })
    },

    getFrontendCareerInfoById({commit} , id) {
        return new Promise((resolve, reject) => {
            getFrontendCareerInfoById(id)
                .then((resp) => {
                    if (resp.data.code === 1) {
                        resolve(resp.data.data)
                    }
                    reject("查询异常！")
                })
                .catch((error) => {
                    reject(error)
                })
        })
    },

    likeQueryByName({ commit }, data) {
        return new Promise((resolve, reject) => {
            likeQueryByName(data).then(
                resp => {
                    const { data } = resp.data
                    resolve(resp.data)
                }).catch(
                error => {
                    reject(error)
                })
        })
    },
}

export default {
    namespaced: true,
    state,
    mutations,
    actions
}
